package com.koron.order.repair.service.impl;

import com.koron.common.core.util.CodeTools;
import com.koron.order.repair.bean.entity.RepairItemParamsPo;
import com.koron.order.repair.mapper.RepairItemParamsMapper;
import com.koron.order.repair.service.RepairItemParamsService;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.koron.ebs.mybatis.SessionFactory;
import org.koron.ebs.mybatis.TaskAnnotation;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * (RepairItemParams)表服务实现类
 *
 * @author zhouj
 * @since 2021-09-23 16:00:01
 */
@Service("repairItemParamsService")
public class RepairItemParamsServiceImpl implements RepairItemParamsService {

    @Override
    @TaskAnnotation("insert")
    public int insert(SessionFactory factory, RepairItemParamsPo repairItemParams) {

        RepairItemParamsMapper mapper = factory.getMapper(RepairItemParamsMapper.class);

        return mapper.insert(repairItemParams);
    }

    @Override
    @TaskAnnotation("insertBatch")
    public int insertBatch(SessionFactory factory, List<RepairItemParamsPo> repairItemParams) {

        if (CollectionUtils.isEmpty(repairItemParams)) {
            return 0;
        }
        RepairItemParamsMapper mapper = factory.getMapper(RepairItemParamsMapper.class);
        
        repairItemParams.forEach(p -> {
            if (StringUtils.isEmpty(p.getId())) {
                p.setId(CodeTools.getCode32());
            }
        });

        return mapper.insertBatch(repairItemParams);
    }

    @Override
    @TaskAnnotation("update")
    public int update(SessionFactory factory, RepairItemParamsPo repairItemParams) {
        RepairItemParamsMapper mapper = factory.getMapper(RepairItemParamsMapper.class);
        return mapper.update(repairItemParams);
    }

    @Override
    @TaskAnnotation("deleteById")
    public int deleteById(SessionFactory factory, String id) {

        RepairItemParamsMapper mapper = factory.getMapper(RepairItemParamsMapper.class);
        return mapper.deleteById(id);
    }

    @Override
    @TaskAnnotation("deleteByItemId")
    public int deleteByItemId(SessionFactory factory, String itemId) {

        RepairItemParamsMapper mapper = factory.getMapper(RepairItemParamsMapper.class);
        return mapper.deleteByItemId(itemId);
    }

    @Override
    @TaskAnnotation("deleteByRepairId")
    public int deleteByRepairId(SessionFactory factory, String repairId) {
        RepairItemParamsMapper mapper = factory.getMapper(RepairItemParamsMapper.class);
        return mapper.deleteByRepairId(repairId);
    }

    @Override
    @TaskAnnotation("queryById")
    public RepairItemParamsPo queryById(SessionFactory factory, String id) {

        RepairItemParamsMapper mapper = factory.getMapper(RepairItemParamsMapper.class);

        return mapper.queryById(id);
    }

    @Override
    @TaskAnnotation("queryList")
    public List<RepairItemParamsPo> queryList(SessionFactory factory, RepairItemParamsPo repairItemParams) {

        RepairItemParamsMapper mapper = factory.getMapper(RepairItemParamsMapper.class);

        List<RepairItemParamsPo> list = mapper.queryList(repairItemParams);

        return list;
    }

}